CC      = /usr/local/share/codesourcery/bin/arm-none-linux-gnueabi-gcc
LFLAGS  = -lm -lpthread -pg
LFLAGS  = -lm -pg
LDFLAGS =  
CFLAGS  =  -pg -g
INCS    = -I.
LPATH	=
SRCS	= main.c bbox.c cr.c env.c fbuf.c geo.c huprn.c husetup.c hutv.c isect.c matrix.c memory.c poly.c raystack.c shade.c sph.c trace.c tri.c workpool.c
EXEC    = RAYTRACE
INPUT	= teapot
# INPUT	= balls4
# INPUT	= car
cmdline	= ./$(EXEC) -p1 inputs/$(INPUT).env
OBJS	= $(SRCS:%.c=%.o)

all: $(EXEC)

$(EXEC) : $(OBJS)
	$(CC) $(LPATH) $(LIBS) $(OBJS) -o $(EXEC) $(LFLAGS) $(LDFLAGS)

%.o : %.c
	$(CC) $(CFLAGS) $(INCS) -c $< -o $@

#RL2TIFF:
#	make -C rl2tiff/ all

gprof: CFLAGS=-O2 -g -pg
gprof: LDFLAGS=-pg
gprof:clean all run
	gprof -b $(EXEC) > gprof.txt
	gprof2pdf.sh gprof.txt

quad: CFLAGS=-O2 -g -pg
quad: LDFLAGS=-pg
quad: clean all run
	pin -t $(QUADHOME)/QUAD.so -ignore_stack_access -applic $(EXEC) -- $(cmdline)

run: $(EXEC)
	$(cmdline)
	rl2tiff/rl2tiff inputs/$(INPUT).rl inputs/$(INPUT).tiff
	tiff2pdf inputs/$(INPUT).tiff -o inputs/$(INPUT).pdf

clean:
	rm -f $(EXEC) $(OBJS) *~ gmon.out

submit: clean
	rm -f inputs/*.tiff inputs/*.pdf	#delete output files produced
	make -C rl2tiff clean			#clean rl2tiff converter dir
	astyle --style=allman $(SRCS)		#re-style the code to allman
	rm -f *.orig				#remove any temporary re-styling files 

.PHONY: clean run all

